package c.h.a.x.s;

import android.graphics.Canvas;
import android.graphics.Paint.Align;
import c.d.a.a.c.d;
import c.d.a.a.c.j;
import c.d.a.a.c.k.a;
import c.d.a.a.i.h;
import c.d.a.a.j.e;
import c.d.a.a.j.g;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieEntry;
import java.util.List;
import java.util.Objects;

/* compiled from: CustomPieChartRenderer */
public class m extends h {
    public m(PieChart pieChart) {
        super(pieChart, pieChart.getAnimator(), pieChart.getViewPortHandler());
    }

    public void e(Canvas canvas) {
        float f;
        float f2;
        Canvas canvas2;
        Canvas canvas3 = canvas;
        a aVar = a.INSIDE_SLICE;
        a aVar2 = a.OUTSIDE_SLICE;
        e.a centerCircleBox = this.f.getCenterCircleBox();
        float radius = this.f.getRadius();
        float rotationAngle = this.f.getRotationAngle();
        float[] drawAngles = this.f.getDrawAngles();
        float[] absoluteAngles = this.f.getAbsoluteAngles();
        Objects.requireNonNull(this.b);
        Objects.requireNonNull(this.b);
        float holeRadius = (radius - ((this.f.getHoleRadius() * radius) / 100.0f)) / 2.0f;
        float holeRadius2 = this.f.getHoleRadius() / 100.0f;
        float f3 = (radius / 10.0f) * 3.6f;
        PieChart pieChart = this.f;
        if (pieChart.O) {
            f3 = (radius - (radius * holeRadius2)) / 2.0f;
            if (pieChart.P || !pieChart.R) {
                f = f3;
            } else {
                f = f3;
                rotationAngle = (float) ((((double) (holeRadius * 360.0f)) / (((double) radius) * 6.283185307179586d)) + ((double) rotationAngle));
            }
            f2 = rotationAngle;
            f3 = f;
        } else {
            f2 = rotationAngle;
        }
        float f4 = radius - f3;
        d dVar = (j) pieChart.getData();
        List list = dVar.i;
        float k = dVar.k();
        boolean z = this.f.L;
        canvas.save();
        f = g.d(5.0f);
        int i = 0;
        int i2 = 0;
        while (i2 < list.size()) {
            d dVar2;
            List list2;
            int i3;
            float f5;
            float f6;
            float[] fArr;
            boolean z2;
            a aVar3;
            a aVar4;
            float[] fArr2;
            e.a aVar5;
            float f7;
            c.d.a.a.f.b.d dVar3 = (c.d.a.a.f.b.h) list.get(i2);
            boolean V = dVar3.V();
            if (V || z) {
                dVar2 = dVar;
                a c = dVar3.c();
                list2 = list;
                a v = dVar3.v();
                a(dVar3);
                int i4 = i;
                i3 = i2;
                float d = g.d(4.0f) + ((float) g.a(this.e, "Q"));
                c.d.a.a.d.e h0 = dVar3.h0();
                i = dVar3.i0();
                e.a aVar6 = centerCircleBox;
                float f8 = radius;
                this.i.setColor(dVar3.v0());
                this.i.setStrokeWidth(g.d(dVar3.a()));
                float i5 = i(dVar3);
                e.a c2 = c.d.a.a.j.d.c(dVar3.j0());
                f5 = holeRadius2;
                c2.b = g.d(c2.b);
                c2.c = g.d(c2.c);
                int i6 = 0;
                while (i6 < i) {
                    float f9;
                    int i7;
                    c.d.a.a.d.e eVar;
                    c.d.a.a.f.b.d dVar4;
                    a aVar7;
                    a aVar8;
                    String str;
                    e.a aVar9 = c2;
                    PieEntry pieEntry = (PieEntry) dVar3.q0(i6);
                    if (i4 == 0) {
                        f9 = 0.0f;
                    } else {
                        f9 = absoluteAngles[i4 - 1] * 1.0f;
                    }
                    f9 = i5;
                    i5 = ((((drawAngles[i4] - ((i5 / (f4 * 0.017453292f)) / 2.0f)) / 2.0f) + f9) * 1.0f) + f2;
                    f6 = f2;
                    if (this.f.Q) {
                        f2 = (pieEntry.a / k) * 100.0f;
                    } else {
                        f2 = pieEntry.a;
                    }
                    if (f2 < 1.0f) {
                        fArr = drawAngles;
                        if (i > 6) {
                            i4++;
                            i7 = i;
                            eVar = h0;
                            z2 = z;
                            aVar3 = aVar;
                            aVar4 = aVar2;
                            fArr2 = absoluteAngles;
                            aVar5 = aVar6;
                            f7 = f8;
                            dVar4 = dVar3;
                            aVar7 = v;
                            aVar8 = c;
                            canvas2 = canvas;
                            i6++;
                            dVar3 = dVar4;
                            v = aVar7;
                            c = aVar8;
                            c2 = aVar9;
                            i5 = f9;
                            f2 = f6;
                            absoluteAngles = fArr2;
                            i = i7;
                            f8 = f7;
                            z = z2;
                            aVar = aVar3;
                            h0 = eVar;
                            aVar2 = aVar4;
                            aVar6 = aVar5;
                            drawAngles = fArr;
                        }
                    } else {
                        fArr = drawAngles;
                    }
                    String b = h0.b(f2, pieEntry);
                    i7 = i;
                    String e = c.b.a.a.a.e(new StringBuilder(), pieEntry.d, " ", b);
                    fArr2 = absoluteAngles;
                    double d2 = (double) (i5 * 0.017453292f);
                    rotationAngle = i5;
                    String str2 = e;
                    float cos = (float) Math.cos(d2);
                    i5 = (float) Math.sin(d2);
                    Object obj = 1;
                    Object obj2 = (z && c == aVar2) ? 1 : null;
                    Object obj3 = (V && v == aVar2) ? 1 : null;
                    Object obj4 = (z && c == aVar) ? 1 : null;
                    if (!(V && v == aVar)) {
                        obj = null;
                    }
                    if (obj2 == null && obj3 == null) {
                        eVar = h0;
                        z2 = z;
                        aVar3 = aVar;
                        aVar4 = aVar2;
                        aVar5 = aVar6;
                        f7 = f8;
                        str = str2;
                        dVar4 = dVar3;
                        aVar7 = v;
                        aVar8 = c;
                        canvas2 = canvas;
                    } else {
                        float f10;
                        float f11;
                        float f12;
                        f7 = dVar3.b();
                        float E = dVar3.E();
                        eVar = h0;
                        f3 = dVar3.T() / 100.0f;
                        z2 = z;
                        if (this.f.O) {
                            f10 = f8 * f5;
                            aVar3 = aVar;
                            f11 = f8;
                            f3 = c.b.a.a.a.a(f11, f10, f3, f10);
                        } else {
                            aVar3 = aVar;
                            f11 = f8;
                            f3 *= f11;
                        }
                        E = dVar3.x() ? (E * f4) * ((float) Math.abs(Math.sin(d2))) : E * f4;
                        f10 = f3 * cos;
                        aVar5 = aVar6;
                        float f13 = aVar5.b;
                        f10 += f13;
                        f3 *= i5;
                        aVar7 = v;
                        float f14 = aVar5.c;
                        f3 += f14;
                        f7 = (f7 + 1.0f) * f4;
                        f13 = (f7 * cos) + f13;
                        float f15 = (f7 * i5) + f14;
                        aVar8 = c;
                        double d3 = ((double) rotationAngle) % 360.0d;
                        if (d3 < 90.0d || d3 > 270.0d) {
                            E = f13 + E;
                            this.e.setTextAlign(Align.LEFT);
                            if (obj2 != null) {
                                this.k.setTextAlign(Align.LEFT);
                            }
                            f14 = E + f;
                        } else {
                            rotationAngle = f13 - E;
                            this.e.setTextAlign(Align.RIGHT);
                            if (obj2 != null) {
                                this.k.setTextAlign(Align.RIGHT);
                            }
                            f14 = rotationAngle - f;
                            E = rotationAngle;
                        }
                        float f16 = f14;
                        if (dVar3.v0() != 1122867) {
                            if (dVar3.L()) {
                                this.i.setColor(dVar3.A0(i6));
                            }
                            Canvas canvas4 = canvas;
                            f7 = f11;
                            dVar4 = dVar3;
                            f14 = f15;
                            aVar4 = aVar2;
                            f12 = f16;
                            canvas4.drawLine(f10, f3, f13, f14, this.i);
                            canvas4.drawLine(f13, f15, E, f14, this.i);
                        } else {
                            f7 = f11;
                            aVar4 = aVar2;
                            dVar4 = dVar3;
                            f12 = f16;
                        }
                        if (obj2 == null || obj3 == null) {
                            canvas2 = canvas;
                            f3 = f15;
                            str = str2;
                            if (obj2 != null) {
                                if (i6 < dVar2.e() && str != null) {
                                    canvas2.drawText(str, f12, (d / 2.0f) + f3, this.k);
                                }
                            } else if (obj3 != null) {
                                rotationAngle = (d / 2.0f) + f3;
                                this.e.setColor(dVar4.s(i6));
                                canvas2.drawText(b, f12, rotationAngle, this.e);
                            }
                        } else {
                            this.e.setColor(dVar4.s(i6));
                            canvas2 = canvas;
                            f3 = f15;
                            canvas2.drawText(b, f12, f3, this.e);
                            if (i6 >= dVar2.e() || str2 == null) {
                                str = str2;
                            } else {
                                str = str2;
                                canvas2.drawText(str, f12, f3 + d, this.k);
                            }
                        }
                    }
                    if (!(obj4 == null && obj == null)) {
                        rotationAngle = (f4 * cos) + aVar5.b;
                        i5 = (i5 * f4) + aVar5.c;
                        this.e.setTextAlign(Align.CENTER);
                        if (obj4 != null && obj != null) {
                            this.e.setColor(dVar4.s(i6));
                            canvas2.drawText(b, rotationAngle, i5, this.e);
                            if (i6 < dVar2.e() && str != null) {
                                canvas2.drawText(str, rotationAngle, i5 + d, this.k);
                            }
                        } else if (obj4 != null) {
                            if (i6 < dVar2.e() && str != null) {
                                canvas2.drawText(str, rotationAngle, (d / 2.0f) + i5, this.k);
                            }
                        } else if (obj != null) {
                            f3 = (d / 2.0f) + i5;
                            this.e.setColor(dVar4.s(i6));
                            canvas2.drawText(b, rotationAngle, f3, this.e);
                        }
                    }
                    i4++;
                    i6++;
                    dVar3 = dVar4;
                    v = aVar7;
                    c = aVar8;
                    c2 = aVar9;
                    i5 = f9;
                    f2 = f6;
                    absoluteAngles = fArr2;
                    i = i7;
                    f8 = f7;
                    z = z2;
                    aVar = aVar3;
                    h0 = eVar;
                    aVar2 = aVar4;
                    aVar6 = aVar5;
                    drawAngles = fArr;
                }
                canvas2 = canvas;
                z2 = z;
                f6 = f2;
                aVar3 = aVar;
                aVar4 = aVar2;
                fArr = drawAngles;
                fArr2 = absoluteAngles;
                aVar5 = aVar6;
                f7 = f8;
                c.d.a.a.j.d.d.c(c2);
                i = i4;
            } else {
                canvas2 = canvas;
                i3 = i2;
                z2 = z;
                list2 = list;
                dVar2 = dVar;
                f6 = f2;
                aVar3 = aVar;
                aVar4 = aVar2;
                f7 = radius;
                fArr = drawAngles;
                fArr2 = absoluteAngles;
                f5 = holeRadius2;
                aVar5 = centerCircleBox;
            }
            i2 = i3 + 1;
            centerCircleBox = aVar5;
            dVar = dVar2;
            list = list2;
            holeRadius2 = f5;
            f2 = f6;
            absoluteAngles = fArr2;
            drawAngles = fArr;
            radius = f7;
            z = z2;
            aVar = aVar3;
            aVar2 = aVar4;
        }
        canvas2 = canvas;
        c.d.a.a.j.d.d.c(centerCircleBox);
        canvas.restore();
    }
}
